{
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {
        "colab_type": "text",
        "id": "view-in-github"
      },
      "source": [
        "<a href=\"https://colab.research.google.com/github/smokett/Intro_To_ML_cw1/blob/master/IntroToMLCW1.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 3,
      "metadata": {
        "id": "C_YL_LbKTUuf"
      },
      "outputs": [],
      "source": [
        "import numpy as np\n",
        "import matplotlib.pyplot as plt\n",
        "%matplotlib inline"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "CSsXQy8DqeLX"
      },
      "source": [
        "# Step 1: Importing data"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 4,
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "HvaMvt77pzY5",
        "outputId": "80f1c3ac-15b0-4068-a775-1dfba397821c"
      },
      "outputs": [
        {
          "name": "stdout",
          "output_type": "stream",
          "text": [
            "(2000, 8)\n",
            "[[-64. -56. -61. ... -82. -81.   1.]\n",
            " [-68. -57. -61. ... -85. -85.   1.]\n",
            " [-63. -60. -60. ... -85. -84.   1.]\n",
            " ...\n",
            " [-62. -59. -46. ... -87. -88.   4.]\n",
            " [-62. -58. -52. ... -90. -85.   4.]\n",
            " [-59. -50. -45. ... -88. -87.   4.]]\n"
          ]
        }
      ],
      "source": [
        "#  importing data from files\n",
        "\n",
        "clean_data = np.loadtxt('wifi_db/clean_dataset.txt')\n",
        "noisy_data = np.loadtxt('wifi_db/noisy_dataset.txt')\n",
        "print(clean_data.shape)\n",
        "print(clean_data)"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 2,
      "metadata": {
        "id": "4D-X7Xx07vwq"
      },
      "outputs": [],
      "source": []
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "-H7MP-u4qitC"
      },
      "source": [
        "# Step 2: Creating Decision Trees"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "flFgi3S5pgOL"
      },
      "source": [
        "## 2.1 Defining the functions to calculate information Gain\n",
        "\n",
        "Functions below will calculate the information gain after we split the dataset to `S_left`, `S_right`"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 5,
      "metadata": {
        "id": "8FWfpKqsvaHx"
      },
      "outputs": [],
      "source": [
        "# this part in the notebook calculates the information gain from entropy and reamainder after made the decision\n",
        "\n",
        "def gain_function(s_all,s_left,s_right):\n",
        "  '''\n",
        "  This function calculates the information gain\n",
        "  '''\n",
        "  return entropy_function(s_all) - remainder_function(s_left,s_right) \n",
        "  \n",
        "\n",
        "def entropy_function(dataset):\n",
        "  '''\n",
        "  This function calculates the entropy of the dataset\n",
        "  '''\n",
        "  if len(dataset) > 0:\n",
        "    labels = dataset[:,-1]\n",
        "    unique, count = np.unique(labels, return_counts=True)\n",
        "    # print(unique,count)\n",
        "    p = [number/len(labels) for number in count]\n",
        "    # print(p)\n",
        "\n",
        "    result = - np.dot(p,np.log2(p))\n",
        "    return result\n",
        "\n",
        "\n",
        "def remainder_function(s_left, s_right):\n",
        "  '''\n",
        "  This function calculate the remainder after made the decision\n",
        "  '''\n",
        "\n",
        "  result = entropy_function(s_left) * len(s_left)/(len(s_left)+len(s_right)) + entropy_function(s_right) * len(s_right)/(len(s_left)+len(s_right))\n",
        "  return result"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 6,
      "metadata": {
        "id": "HDuyw_nIp-il"
      },
      "outputs": [],
      "source": [
        "def decision_tree_learning(training_dataset, depth):\n",
        "  \n",
        "  pass"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "CjWHqOhafLBz"
      },
      "source": [
        "## 2.2 FIND_SPLIT function\n",
        "This function will find the split that give us the most ***information gain(IG)***, IG is got from the defined function above. \n",
        "\n",
        "The general idea is that it will try to make a split in every **wifi** data (i.e.**wifi1**), using every value for each wifi as a threshold to split, and find the split that give us the most IG.\n",
        "\n",
        "----------------------------------\n",
        "In the function below, a `checked_value` list is implemented to let the program run faster. So basically There will be many duplicated values in each wifi signals. What we will do is to `sort` the data first to get the value in order, and to check if the same value has been examined. In decision tree, there will be no need for us to do the same split for the same threshold. By having checking if the value has already been considered as a threshold, we are able to `make the split and calculate the IG only when encounter another unique value in the set`. By doing this we shortened our calculation process dramatically.(1999 --> 54)"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 7,
      "metadata": {
        "id": "dZ1P3evex-4N"
      },
      "outputs": [],
      "source": [
        "def find_split(dataset):\n",
        "  '''\n",
        "  This function finds the split that will generate the highest information gain\n",
        "\n",
        "  Input: dataset: this will be the input dataset, could be subsets that in leaf nodes\n",
        "          The dataset is in dimension(...,8), with the last row element the label\n",
        "  \n",
        "  Output: S_left, S_left: this seperates the dataset into two parts that will generate the highest information gain\n",
        "  '''\n",
        "  # each row in wifis will be a wifi emitter's attribute, [:,-1] takes away the label\n",
        " \n",
        "  # set the initial values\n",
        "  highest_gain = -1\n",
        "  best_cut = None\n",
        "  best_left = None\n",
        "  best_right = None\n",
        "\n",
        "\n",
        "  \n",
        "  #for each column in the dataset\n",
        "  for col_num in range(0,len(dataset[0])-1):\n",
        "    # get the sorted dataset according to the corresponding col\n",
        "    args = np.argsort(dataset[:,col_num])\n",
        "    sorted_data = dataset[args]\n",
        "    # initial checked_value\n",
        "    checked_value = []\n",
        "    \n",
        "    # start from the second until the last, so that left_set and right_set will not be empty\n",
        "    # the last split would be dataset[:-1],dataset[-1]\n",
        "    for row_num in range(1,len(dataset)):\n",
        "      value = sorted_data[row_num,col_num]\n",
        "      if value not in checked_value:\n",
        "        checked_value.append(value)\n",
        "        left_set = sorted_data[:row_num]\n",
        "        right_set = sorted_data[row_num:]\n",
        "        if left_set is [] or right_set is []:\n",
        "          print('There is an empty list!')\n",
        "        IG = gain_function(dataset, left_set, right_set)\n",
        "        \n",
        "        if IG > highest_gain:\n",
        "          best_split_number,best_split_col = sorted_data[row_num,col_num],col_num\n",
        "          best_left = left_set\n",
        "          best_right = right_set\n",
        "          highest_gain = IG\n",
        "    # This is for checking purpose\n",
        "    # print(len(checked_value)) !!! remember we have excluted the first row, so the actual unique value in the list might be plus 1! \n",
        "  return best_left,best_right,best_split_number,best_split_col\n",
        "\n",
        "  \n",
        "\n",
        "\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 10,
      "metadata": {
        "id": "_WObTsgyw59z"
      },
      "outputs": [],
      "source": [
        "s_left,s_right,cut,pos = find_split(clean_data)"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 11,
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "KD4bVoPSDjZq",
        "outputId": "63d68cfb-1b74-45a9-aea3-99ae54a83dca"
      },
      "outputs": [
        {
          "name": "stdout",
          "output_type": "stream",
          "text": [
            "(1012, 8)\n",
            "(988, 8)\n",
            "-54.0\n",
            "in column 0\n"
          ]
        }
      ],
      "source": [
        "################################## for testing purpose###########################\n",
        "print(s_left.shape)\n",
        "print(s_right.shape)\n",
        "print(cut)\n",
        "print('in column',pos)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "8ua8LyWgrK-g"
      },
      "source": [
        "## 2.3 Node Class\n",
        "\n",
        "This section we will create a tree class, which will take the s_left and s_right as its attrribtes, and also keep track of its depth."
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 8,
      "metadata": {
        "id": "sUvq6YsQw8ur"
      },
      "outputs": [],
      "source": [
        "class Node :\n",
        "  '''\n",
        "  This is the Node class, we will create a node everytime we make a split\n",
        "  INPUT: \n",
        "          depth: the depth of the node\n",
        "          threshold: the value, and its wifi number this node used to split the data\n",
        "  '''\n",
        "  def __init__(self,attribute,value,s_left,s_right,is_leaf):\n",
        "    self.attribute = attribute\n",
        "    self.value = value\n",
        "    self.left = s_left\n",
        "    self.right = s_right\n",
        "    self.is_leaf = is_leaf\n",
        "\n",
        "  def draw_node(self):\n",
        "    pass\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 8,
      "metadata": {
        "id": "9nQWyFUSAZ4c"
      },
      "outputs": [],
      "source": []
    },
    {
      "cell_type": "code",
      "execution_count": 9,
      "metadata": {
        "id": "TO_6LzuXAfNn"
      },
      "outputs": [],
      "source": [
        "def decision_tree_learning_function(training_dataset,depth):\n",
        "  labels = training_dataset[:,-1]\n",
        "  uni_label,label_counts = np.unique(labels,return_counts=True)\n",
        "  {}\n",
        "  if len(uni_label) == 1:\n",
        "    node = {'attr':None,\n",
        "        'value':uni_label[0],\n",
        "        'left':None,\n",
        "        'right':None,\n",
        "        'is_leaf':True}\n",
        "    return node,depth\n",
        "  else:\n",
        "    s_l,s_r,threshold,col_pos = find_split(training_dataset)\n",
        "\n",
        "    l_branch,l_depth = decision_tree_learning_function(s_l,depth+1)\n",
        "    r_branch,r_depth = decision_tree_learning_function(s_r,depth+1)\n",
        "\n",
        "    node = {'attr':col_pos,\n",
        "        'value':threshold,\n",
        "        'left':l_branch,\n",
        "        'right':r_branch,\n",
        "        'is_leaf':False}\n",
        "    \n",
        "\n",
        "    return node, max(l_depth,r_depth)\n",
        "\n",
        "\n",
        "  \n",
        "    \n",
        "    \n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 10,
      "metadata": {
        "id": "T4vDgow9uvG0"
      },
      "outputs": [],
      "source": [
        "node_result,depth_result = decision_tree_learning_function(clean_data,0)"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 11,
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "cTaXl0hiwiDq",
        "outputId": "2ff24639-2295-4603-95fc-fba0aae5248f"
      },
      "outputs": [
        {
          "name": "stdout",
          "output_type": "stream",
          "text": [
            "{'attr': 0, 'value': -54.0, 'left': {'attr': 4, 'value': -59.0, 'left': {'attr': 3, 'value': -55.0, 'left': {'attr': 2, 'value': -55.0, 'left': {'attr': None, 'value': 1.0, 'left': None, 'right': None, 'is_leaf': True}, 'right': {'attr': 6, 'value': -85.0, 'left': {'attr': 4, 'value': -62.0, 'left': {'attr': 5, 'value': -85.0, 'left': {'attr': 0, 'value': -56.0, 'left': {'attr': None, 'value': 4.0, 'left': None, 'right': None, 'is_leaf': True}, 'right': {'attr': None, 'value': 3.0, 'left': None, 'right': None, 'is_leaf': True}, 'is_leaf': False}, 'right': {'attr': None, 'value': 1.0, 'left': None, 'right': None, 'is_leaf': True}, 'is_leaf': False}, 'right': {'attr': None, 'value': 4.0, 'left': None, 'right': None, 'is_leaf': True}, 'is_leaf': False}, 'right': {'attr': None, 'value': 1.0, 'left': None, 'right': None, 'is_leaf': True}, 'is_leaf': False}, 'is_leaf': False}, 'right': {'attr': 1, 'value': -50.0, 'left': {'attr': None, 'value': 3.0, 'left': None, 'right': None, 'is_leaf': True}, 'right': {'attr': 0, 'value': -58.0, 'left': {'attr': None, 'value': 3.0, 'left': None, 'right': None, 'is_leaf': True}, 'right': {'attr': None, 'value': 1.0, 'left': None, 'right': None, 'is_leaf': True}, 'is_leaf': False}, 'is_leaf': False}, 'is_leaf': False}, 'right': {'attr': 4, 'value': -56.0, 'left': {'attr': 3, 'value': -58.0, 'left': {'attr': None, 'value': 4.0, 'left': None, 'right': None, 'is_leaf': True}, 'right': {'attr': None, 'value': 3.0, 'left': None, 'right': None, 'is_leaf': True}, 'is_leaf': False}, 'right': {'attr': None, 'value': 4.0, 'left': None, 'right': None, 'is_leaf': True}, 'is_leaf': False}, 'is_leaf': False}, 'right': {'attr': 0, 'value': -44.0, 'left': {'attr': 4, 'value': -70.0, 'left': {'attr': 3, 'value': -48.0, 'left': {'attr': 2, 'value': -57.0, 'left': {'attr': 0, 'value': -50.0, 'left': {'attr': None, 'value': 3.0, 'left': None, 'right': None, 'is_leaf': True}, 'right': {'attr': None, 'value': 2.0, 'left': None, 'right': None, 'is_leaf': True}, 'is_leaf': False}, 'right': {'attr': None, 'value': 3.0, 'left': None, 'right': None, 'is_leaf': True}, 'is_leaf': False}, 'right': {'attr': 1, 'value': -58.0, 'left': {'attr': 1, 'value': -59.0, 'left': {'attr': None, 'value': 2.0, 'left': None, 'right': None, 'is_leaf': True}, 'right': {'attr': None, 'value': 3.0, 'left': None, 'right': None, 'is_leaf': True}, 'is_leaf': False}, 'right': {'attr': None, 'value': 2.0, 'left': None, 'right': None, 'is_leaf': True}, 'is_leaf': False}, 'is_leaf': False}, 'right': {'attr': 3, 'value': -39.0, 'left': {'attr': 4, 'value': -53.0, 'left': {'attr': 2, 'value': -53.0, 'left': {'attr': 5, 'value': -77.0, 'left': {'attr': 3, 'value': -48.0, 'left': {'attr': 6, 'value': -76.0, 'left': {'attr': None, 'value': 3.0, 'left': None, 'right': None, 'is_leaf': True}, 'right': {'attr': 5, 'value': -85.0, 'left': {'attr': None, 'value': 2.0, 'left': None, 'right': None, 'is_leaf': True}, 'right': {'attr': None, 'value': 3.0, 'left': None, 'right': None, 'is_leaf': True}, 'is_leaf': False}, 'is_leaf': False}, 'right': {'attr': 6, 'value': -77.0, 'left': {'attr': 4, 'value': -68.0, 'left': {'attr': None, 'value': 2.0, 'left': None, 'right': None, 'is_leaf': True}, 'right': {'attr': 1, 'value': -55.0, 'left': {'attr': 2, 'value': -55.0, 'left': {'attr': None, 'value': 3.0, 'left': None, 'right': None, 'is_leaf': True}, 'right': {'attr': 2, 'value': -54.0, 'left': {'attr': 0, 'value': -45.0, 'left': {'attr': None, 'value': 2.0, 'left': None, 'right': None, 'is_leaf': True}, 'right': {'attr': None, 'value': 3.0, 'left': None, 'right': None, 'is_leaf': True}, 'is_leaf': False}, 'right': {'attr': None, 'value': 3.0, 'left': None, 'right': None, 'is_leaf': True}, 'is_leaf': False}, 'is_leaf': False}, 'right': {'attr': None, 'value': 3.0, 'left': None, 'right': None, 'is_leaf': True}, 'is_leaf': False}, 'is_leaf': False}, 'right': {'attr': 2, 'value': -54.0, 'left': {'attr': None, 'value': 2.0, 'left': None, 'right': None, 'is_leaf': True}, 'right': {'attr': 0, 'value': -45.0, 'left': {'attr': None, 'value': 3.0, 'left': None, 'right': None, 'is_leaf': True}, 'right': {'attr': None, 'value': 2.0, 'left': None, 'right': None, 'is_leaf': True}, 'is_leaf': False}, 'is_leaf': False}, 'is_leaf': False}, 'is_leaf': False}, 'right': {'attr': 4, 'value': -67.0, 'left': {'attr': None, 'value': 2.0, 'left': None, 'right': None, 'is_leaf': True}, 'right': {'attr': 6, 'value': -73.0, 'left': {'attr': 4, 'value': -64.0, 'left': {'attr': 0, 'value': -49.0, 'left': {'attr': None, 'value': 3.0, 'left': None, 'right': None, 'is_leaf': True}, 'right': {'attr': 4, 'value': -67.0, 'left': {'attr': None, 'value': 3.0, 'left': None, 'right': None, 'is_leaf': True}, 'right': {'attr': None, 'value': 2.0, 'left': None, 'right': None, 'is_leaf': True}, 'is_leaf': False}, 'is_leaf': False}, 'right': {'attr': None, 'value': 3.0, 'left': None, 'right': None, 'is_leaf': True}, 'is_leaf': False}, 'right': {'attr': None, 'value': 2.0, 'left': None, 'right': None, 'is_leaf': True}, 'is_leaf': False}, 'is_leaf': False}, 'is_leaf': False}, 'right': {'attr': 6, 'value': -71.0, 'left': {'attr': None, 'value': 3.0, 'left': None, 'right': None, 'is_leaf': True}, 'right': {'attr': None, 'value': 2.0, 'left': None, 'right': None, 'is_leaf': True}, 'is_leaf': False}, 'is_leaf': False}, 'right': {'attr': None, 'value': 4.0, 'left': None, 'right': None, 'is_leaf': True}, 'is_leaf': False}, 'right': {'attr': None, 'value': 2.0, 'left': None, 'right': None, 'is_leaf': True}, 'is_leaf': False}, 'is_leaf': False}, 'right': {'attr': 3, 'value': -47.0, 'left': {'attr': 0, 'value': -42.0, 'left': {'attr': None, 'value': 3.0, 'left': None, 'right': None, 'is_leaf': True}, 'right': {'attr': 0, 'value': -42.0, 'left': {'attr': None, 'value': 3.0, 'left': None, 'right': None, 'is_leaf': True}, 'right': {'attr': None, 'value': 2.0, 'left': None, 'right': None, 'is_leaf': True}, 'is_leaf': False}, 'is_leaf': False}, 'right': {'attr': None, 'value': 2.0, 'left': None, 'right': None, 'is_leaf': True}, 'is_leaf': False}, 'is_leaf': False}, 'is_leaf': False}\n"
          ]
        }
      ],
      "source": [
        "print(node_result)"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 12,
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "fT2rE2IoowuR",
        "outputId": "7ef574e9-85b9-4487-d658-0976173f46c5"
      },
      "outputs": [
        {
          "data": {
            "text/plain": [
              "{'attr': 0,\n",
              " 'is_leaf': False,\n",
              " 'left': {'attr': 4,\n",
              "  'is_leaf': False,\n",
              "  'left': {'attr': 3,\n",
              "   'is_leaf': False,\n",
              "   'left': {'attr': 2,\n",
              "    'is_leaf': False,\n",
              "    'left': {'attr': None,\n",
              "     'is_leaf': True,\n",
              "     'left': None,\n",
              "     'right': None,\n",
              "     'value': 1.0},\n",
              "    'right': {'attr': 6,\n",
              "     'is_leaf': False,\n",
              "     'left': {'attr': 4,\n",
              "      'is_leaf': False,\n",
              "      'left': {'attr': 5,\n",
              "       'is_leaf': False,\n",
              "       'left': {'attr': 0,\n",
              "        'is_leaf': False,\n",
              "        'left': {'attr': None,\n",
              "         'is_leaf': True,\n",
              "         'left': None,\n",
              "         'right': None,\n",
              "         'value': 4.0},\n",
              "        'right': {'attr': None,\n",
              "         'is_leaf': True,\n",
              "         'left': None,\n",
              "         'right': None,\n",
              "         'value': 3.0},\n",
              "        'value': -56.0},\n",
              "       'right': {'attr': None,\n",
              "        'is_leaf': True,\n",
              "        'left': None,\n",
              "        'right': None,\n",
              "        'value': 1.0},\n",
              "       'value': -85.0},\n",
              "      'right': {'attr': None,\n",
              "       'is_leaf': True,\n",
              "       'left': None,\n",
              "       'right': None,\n",
              "       'value': 4.0},\n",
              "      'value': -62.0},\n",
              "     'right': {'attr': None,\n",
              "      'is_leaf': True,\n",
              "      'left': None,\n",
              "      'right': None,\n",
              "      'value': 1.0},\n",
              "     'value': -85.0},\n",
              "    'value': -55.0},\n",
              "   'right': {'attr': 1,\n",
              "    'is_leaf': False,\n",
              "    'left': {'attr': None,\n",
              "     'is_leaf': True,\n",
              "     'left': None,\n",
              "     'right': None,\n",
              "     'value': 3.0},\n",
              "    'right': {'attr': 0,\n",
              "     'is_leaf': False,\n",
              "     'left': {'attr': None,\n",
              "      'is_leaf': True,\n",
              "      'left': None,\n",
              "      'right': None,\n",
              "      'value': 3.0},\n",
              "     'right': {'attr': None,\n",
              "      'is_leaf': True,\n",
              "      'left': None,\n",
              "      'right': None,\n",
              "      'value': 1.0},\n",
              "     'value': -58.0},\n",
              "    'value': -50.0},\n",
              "   'value': -55.0},\n",
              "  'right': {'attr': 4,\n",
              "   'is_leaf': False,\n",
              "   'left': {'attr': 3,\n",
              "    'is_leaf': False,\n",
              "    'left': {'attr': None,\n",
              "     'is_leaf': True,\n",
              "     'left': None,\n",
              "     'right': None,\n",
              "     'value': 4.0},\n",
              "    'right': {'attr': None,\n",
              "     'is_leaf': True,\n",
              "     'left': None,\n",
              "     'right': None,\n",
              "     'value': 3.0},\n",
              "    'value': -58.0},\n",
              "   'right': {'attr': None,\n",
              "    'is_leaf': True,\n",
              "    'left': None,\n",
              "    'right': None,\n",
              "    'value': 4.0},\n",
              "   'value': -56.0},\n",
              "  'value': -59.0},\n",
              " 'right': {'attr': 0,\n",
              "  'is_leaf': False,\n",
              "  'left': {'attr': 4,\n",
              "   'is_leaf': False,\n",
              "   'left': {'attr': 3,\n",
              "    'is_leaf': False,\n",
              "    'left': {'attr': 2,\n",
              "     'is_leaf': False,\n",
              "     'left': {'attr': 0,\n",
              "      'is_leaf': False,\n",
              "      'left': {'attr': None,\n",
              "       'is_leaf': True,\n",
              "       'left': None,\n",
              "       'right': None,\n",
              "       'value': 3.0},\n",
              "      'right': {'attr': None,\n",
              "       'is_leaf': True,\n",
              "       'left': None,\n",
              "       'right': None,\n",
              "       'value': 2.0},\n",
              "      'value': -50.0},\n",
              "     'right': {'attr': None,\n",
              "      'is_leaf': True,\n",
              "      'left': None,\n",
              "      'right': None,\n",
              "      'value': 3.0},\n",
              "     'value': -57.0},\n",
              "    'right': {'attr': 1,\n",
              "     'is_leaf': False,\n",
              "     'left': {'attr': 1,\n",
              "      'is_leaf': False,\n",
              "      'left': {'attr': None,\n",
              "       'is_leaf': True,\n",
              "       'left': None,\n",
              "       'right': None,\n",
              "       'value': 2.0},\n",
              "      'right': {'attr': None,\n",
              "       'is_leaf': True,\n",
              "       'left': None,\n",
              "       'right': None,\n",
              "       'value': 3.0},\n",
              "      'value': -59.0},\n",
              "     'right': {'attr': None,\n",
              "      'is_leaf': True,\n",
              "      'left': None,\n",
              "      'right': None,\n",
              "      'value': 2.0},\n",
              "     'value': -58.0},\n",
              "    'value': -48.0},\n",
              "   'right': {'attr': 3,\n",
              "    'is_leaf': False,\n",
              "    'left': {'attr': 4,\n",
              "     'is_leaf': False,\n",
              "     'left': {'attr': 2,\n",
              "      'is_leaf': False,\n",
              "      'left': {'attr': 5,\n",
              "       'is_leaf': False,\n",
              "       'left': {'attr': 3,\n",
              "        'is_leaf': False,\n",
              "        'left': {'attr': 6,\n",
              "         'is_leaf': False,\n",
              "         'left': {'attr': None,\n",
              "          'is_leaf': True,\n",
              "          'left': None,\n",
              "          'right': None,\n",
              "          'value': 3.0},\n",
              "         'right': {'attr': 5,\n",
              "          'is_leaf': False,\n",
              "          'left': {'attr': None,\n",
              "           'is_leaf': True,\n",
              "           'left': None,\n",
              "           'right': None,\n",
              "           'value': 2.0},\n",
              "          'right': {'attr': None,\n",
              "           'is_leaf': True,\n",
              "           'left': None,\n",
              "           'right': None,\n",
              "           'value': 3.0},\n",
              "          'value': -85.0},\n",
              "         'value': -76.0},\n",
              "        'right': {'attr': 6,\n",
              "         'is_leaf': False,\n",
              "         'left': {'attr': 4,\n",
              "          'is_leaf': False,\n",
              "          'left': {'attr': None,\n",
              "           'is_leaf': True,\n",
              "           'left': None,\n",
              "           'right': None,\n",
              "           'value': 2.0},\n",
              "          'right': {'attr': 1,\n",
              "           'is_leaf': False,\n",
              "           'left': {'attr': 2,\n",
              "            'is_leaf': False,\n",
              "            'left': {'attr': None,\n",
              "             'is_leaf': True,\n",
              "             'left': None,\n",
              "             'right': None,\n",
              "             'value': 3.0},\n",
              "            'right': {'attr': 2,\n",
              "             'is_leaf': False,\n",
              "             'left': {'attr': 0,\n",
              "              'is_leaf': False,\n",
              "              'left': {'attr': None,\n",
              "               'is_leaf': True,\n",
              "               'left': None,\n",
              "               'right': None,\n",
              "               'value': 2.0},\n",
              "              'right': {'attr': None,\n",
              "               'is_leaf': True,\n",
              "               'left': None,\n",
              "               'right': None,\n",
              "               'value': 3.0},\n",
              "              'value': -45.0},\n",
              "             'right': {'attr': None,\n",
              "              'is_leaf': True,\n",
              "              'left': None,\n",
              "              'right': None,\n",
              "              'value': 3.0},\n",
              "             'value': -54.0},\n",
              "            'value': -55.0},\n",
              "           'right': {'attr': None,\n",
              "            'is_leaf': True,\n",
              "            'left': None,\n",
              "            'right': None,\n",
              "            'value': 3.0},\n",
              "           'value': -55.0},\n",
              "          'value': -68.0},\n",
              "         'right': {'attr': 2,\n",
              "          'is_leaf': False,\n",
              "          'left': {'attr': None,\n",
              "           'is_leaf': True,\n",
              "           'left': None,\n",
              "           'right': None,\n",
              "           'value': 2.0},\n",
              "          'right': {'attr': 0,\n",
              "           'is_leaf': False,\n",
              "           'left': {'attr': None,\n",
              "            'is_leaf': True,\n",
              "            'left': None,\n",
              "            'right': None,\n",
              "            'value': 3.0},\n",
              "           'right': {'attr': None,\n",
              "            'is_leaf': True,\n",
              "            'left': None,\n",
              "            'right': None,\n",
              "            'value': 2.0},\n",
              "           'value': -45.0},\n",
              "          'value': -54.0},\n",
              "         'value': -77.0},\n",
              "        'value': -48.0},\n",
              "       'right': {'attr': 4,\n",
              "        'is_leaf': False,\n",
              "        'left': {'attr': None,\n",
              "         'is_leaf': True,\n",
              "         'left': None,\n",
              "         'right': None,\n",
              "         'value': 2.0},\n",
              "        'right': {'attr': 6,\n",
              "         'is_leaf': False,\n",
              "         'left': {'attr': 4,\n",
              "          'is_leaf': False,\n",
              "          'left': {'attr': 0,\n",
              "           'is_leaf': False,\n",
              "           'left': {'attr': None,\n",
              "            'is_leaf': True,\n",
              "            'left': None,\n",
              "            'right': None,\n",
              "            'value': 3.0},\n",
              "           'right': {'attr': 4,\n",
              "            'is_leaf': False,\n",
              "            'left': {'attr': None,\n",
              "             'is_leaf': True,\n",
              "             'left': None,\n",
              "             'right': None,\n",
              "             'value': 3.0},\n",
              "            'right': {'attr': None,\n",
              "             'is_leaf': True,\n",
              "             'left': None,\n",
              "             'right': None,\n",
              "             'value': 2.0},\n",
              "            'value': -67.0},\n",
              "           'value': -49.0},\n",
              "          'right': {'attr': None,\n",
              "           'is_leaf': True,\n",
              "           'left': None,\n",
              "           'right': None,\n",
              "           'value': 3.0},\n",
              "          'value': -64.0},\n",
              "         'right': {'attr': None,\n",
              "          'is_leaf': True,\n",
              "          'left': None,\n",
              "          'right': None,\n",
              "          'value': 2.0},\n",
              "         'value': -73.0},\n",
              "        'value': -67.0},\n",
              "       'value': -77.0},\n",
              "      'right': {'attr': 6,\n",
              "       'is_leaf': False,\n",
              "       'left': {'attr': None,\n",
              "        'is_leaf': True,\n",
              "        'left': None,\n",
              "        'right': None,\n",
              "        'value': 3.0},\n",
              "       'right': {'attr': None,\n",
              "        'is_leaf': True,\n",
              "        'left': None,\n",
              "        'right': None,\n",
              "        'value': 2.0},\n",
              "       'value': -71.0},\n",
              "      'value': -53.0},\n",
              "     'right': {'attr': None,\n",
              "      'is_leaf': True,\n",
              "      'left': None,\n",
              "      'right': None,\n",
              "      'value': 4.0},\n",
              "     'value': -53.0},\n",
              "    'right': {'attr': None,\n",
              "     'is_leaf': True,\n",
              "     'left': None,\n",
              "     'right': None,\n",
              "     'value': 2.0},\n",
              "    'value': -39.0},\n",
              "   'value': -70.0},\n",
              "  'right': {'attr': 3,\n",
              "   'is_leaf': False,\n",
              "   'left': {'attr': 0,\n",
              "    'is_leaf': False,\n",
              "    'left': {'attr': None,\n",
              "     'is_leaf': True,\n",
              "     'left': None,\n",
              "     'right': None,\n",
              "     'value': 3.0},\n",
              "    'right': {'attr': 0,\n",
              "     'is_leaf': False,\n",
              "     'left': {'attr': None,\n",
              "      'is_leaf': True,\n",
              "      'left': None,\n",
              "      'right': None,\n",
              "      'value': 3.0},\n",
              "     'right': {'attr': None,\n",
              "      'is_leaf': True,\n",
              "      'left': None,\n",
              "      'right': None,\n",
              "      'value': 2.0},\n",
              "     'value': -42.0},\n",
              "    'value': -42.0},\n",
              "   'right': {'attr': None,\n",
              "    'is_leaf': True,\n",
              "    'left': None,\n",
              "    'right': None,\n",
              "    'value': 2.0},\n",
              "   'value': -47.0},\n",
              "  'value': -44.0},\n",
              " 'value': -54.0}"
            ]
          },
          "execution_count": 12,
          "metadata": {},
          "output_type": "execute_result"
        }
      ],
      "source": [
        "node_result"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 12,
      "metadata": {
        "id": "CA6Jl7N7wq75"
      },
      "outputs": [],
      "source": [
        "                                                 "
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 12,
      "metadata": {
        "id": "5ca9ExW-pNIp"
      },
      "outputs": [],
      "source": []
    },
    {
      "cell_type": "code",
      "execution_count": 12,
      "metadata": {
        "id": "YMkf7OCnwQC8"
      },
      "outputs": [],
      "source": []
    }
  ],
  "metadata": {
    "colab": {
      "authorship_tag": "ABX9TyMaeYlzYNzz+2jFcxNQC1bc",
      "collapsed_sections": [],
      "include_colab_link": true,
      "name": "IntroToMLCW1",
      "provenance": []
    },
    "interpreter": {
      "hash": "143efee110dcc95fb039b26bcf6e5aea34ccd475daaa1680bfee5e0ecb85baab"
    },
    "kernelspec": {
      "display_name": "Python 3.7.0 64-bit",
      "name": "python3"
    },
    "language_info": {
      "codemirror_mode": {
        "name": "ipython",
        "version": 3
      },
      "file_extension": ".py",
      "mimetype": "text/x-python",
      "name": "python",
      "nbconvert_exporter": "python",
      "pygments_lexer": "ipython3",
      "version": "3.7.0"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}
